package poset;

import graphs.DirectedConnection;


public class Ordering implements Comparable<Ordering>, DirectedConnection{
	private final Item item1;
	private final Item item2;

	public Ordering(Item item1, Item item2) throws ReflexiveOrderingException{
		if(item1.equals(item2)){
			throw new ReflexiveOrderingException("Orderings cannot be reflexive");
		} else {
			this.item1 = item1;
			this.item2 = item2;
		}
	}

	public Item getItem1() {
		return item1;
	}

	public Item getItem2() {
		return item2;
	}

	@Override
	public int compareTo(Ordering ordering) {
		int firstComparison = item1.compareTo(ordering.getItem1());
		if(firstComparison == 0){
			return item2.compareTo(ordering.getItem2());
		} else {
			return firstComparison;
		}
	}
	
	public String toString(){
		StringBuffer str = new StringBuffer();
		str.append("<").append(item1).append(", ").append(item2).append(">");
		return str.toString();
	}
}
